home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_2.0 / NDK2.0-2 / NewIFF / modules / iffpstrings.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-19  |  3.3 KB  |  179 lines

  1. /* iffpstrings.c
  2.  *
  3.  *  centralized message routine for IFFP modules
  4.  *  If you plan to add international language support to
  5.  *  your iffparse application, all of the iffparse module
  6.  *  strings are here and are accessed via the SI() macro in
  7.  *  iffp/iff.h which calls GetString() 
  8.  *
  9.  *  There is some #ifdef'd out code here which will be useful if you
  10.  *  decide to localize your application when locale.library is released.
  11.  */
  12.  
  13.  
  14. /*
  15. #define LOCALIZED
  16. */
  17.  
  18. #define INCLUDENAME    "iffp/iffpstrings.h"
  19.  
  20. #ifdef LOCALIZED
  21. #define CATALOGNAME    "yourapp.catalog"
  22. #include <clib/locale_protos.h>
  23. #ifndef NO_SAS_PRAGMAS
  24. #include <pragmas/locale_pragmas.h>
  25. #endif
  26. #endif
  27.  
  28. /* Locale stuff */
  29. #define  IFFP_MODULES
  30. #define  STRINGARRAY
  31. #include INCLUDENAME
  32.  
  33. #ifdef LOCALIZED
  34. extern struct Library *LocaleBase;
  35. #endif
  36.  
  37. extern struct AppString AppStrings[];
  38. static APTR   catalog = NULL;
  39.  
  40. /* For reference
  41. struct AppString
  42. {
  43.     LONG   as_ID;
  44.     STRPTR as_Str;
  45. };
  46. */
  47.  
  48. #include "iffp/iff.h"
  49. #include <intuition/screens.h>
  50.  
  51. /* OpenStrings - localizes strings
  52.  * Requires open locale.library to work, but safe to call without
  53.  * You may pass nulls as args if you have no localized application strings
  54.  */
  55.  
  56. #ifdef LOCALIZED
  57. void OpenStrings()
  58.    {
  59.    if((LocaleBase)&&(!catalog))
  60.     {
  61.     catalog = OpenCatalogA(NULL,CATALOGNAME,NULL);
  62.     }
  63.     }
  64. #endif
  65.  
  66. /* CloseStrings - release the localized strings 
  67.  * Make sure all error messages are printed BEFORE calling this function
  68.  */
  69. #ifdef LOCALIZED
  70. void CloseStrings()
  71.     {
  72.     if((LocaleBase)&&(catalog))
  73.     {
  74.         CloseCatalog(catalog);
  75.     }
  76.     }
  77. #endif
  78.  
  79. /*
  80.  * IFFerr
  81.  *
  82.  * Returns pointer to IFF Error string or NULL (no error)
  83.  */
  84. UBYTE *IFFerr(LONG error)
  85. {
  86.     /*
  87.      * English error messages for possible IFFERR_#? returns from various
  88.      * IFF routines.  To get the index into this array, take your IFFERR
  89.      * code, negate it, and subtract one.
  90.      *  idx = -error - 1;
  91.      *
  92.      * To index localized string, then add MSG_IFFP_STDFIRST
  93.      */
  94.  
  95.     static UBYTE unknown[48];
  96.     UBYTE  *s;
  97.  
  98.     if((error < 0)&&(error >= -12))
  99.         {
  100.         s=SI(((-error) - 1) + MSG_IFFP_STDFIRST);
  101.         }
  102.     else if(error = CLIENT_ERROR)
  103.         {
  104.         s=SI(MSG_IFFP_CLIENTERR);
  105.         }
  106.     else if(error = NOFILE)
  107.         {
  108.         s=SI(MSG_IFFP_NOFILE);
  109.         }
  110.     else if(error)
  111.         {
  112.         sprintf(unknown,SI(MSG_IFFP_UNKNOWNERR_D),error);
  113.         s=unknown;
  114.         }
  115.     return(s);
  116. }
  117.  
  118.  
  119. /* OpenScreen error messages
  120.  */
  121. UBYTE *openScreenErr(ULONG errorcode)
  122.    {
  123.    static UBYTE unknown[48];
  124.    UBYTE *s=NULL;
  125.  
  126.         switch ( errorcode )
  127.     {
  128.     case OSERR_NOMEM:
  129.         s=SI(MSG_IFFP_OSNOMEM);
  130.         break;
  131.     case OSERR_NOCHIPMEM:
  132.         s=SI(MSG_IFFP_OSNOCHIPMEM);
  133.         break;
  134.     case OSERR_NOMONITOR:
  135.         s=SI(MSG_IFFP_OSNOMONITOR);
  136.         break;
  137.     case OSERR_NOCHIPS:
  138.         s=SI(MSG_IFFP_OSNOCHIPS);
  139.         break;
  140.     case OSERR_PUBNOTUNIQUE:
  141.         s=SI(MSG_IFFP_OSPUBNOTUNIQUE);
  142.         break;
  143.     case OSERR_UNKNOWNMODE:
  144.         s=SI(MSG_IFFP_OSUNKNOWNMODE);
  145.         break;
  146.     default:
  147.         sprintf(unknown,SI(MSG_IFFP_OSUNKNOWNERR_D),errorcode);
  148.         s=unknown;
  149.     }
  150.     return(s);
  151.     }
  152.  
  153.  
  154. UBYTE *GetString(ULONG id)
  155.     {
  156.     struct AppString *as;
  157.     UBYTE *s = "";
  158.     int k,l;
  159.  
  160.     l = sizeof(AppStrings);
  161.     as = AppStrings;
  162.  
  163.     for(k=0; k<l; k++, as++)
  164.     {
  165.     if(as->as_ID == id)
  166.         {
  167.         s = as->as_Str;
  168.         break;
  169.         }
  170.     }
  171. #ifdef LOCALIZED
  172.     if((LocaleBase)&&(catalog)&&(*s))
  173.     {
  174.     s = GetCatalogStr(catalog,id,s);
  175.     }
  176. #endif
  177.     return(s);
  178.     }
  179.